Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-mutex

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-mutex

A mutex for guarding async workflows

  • 0.2.6
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is async-mutex?

The async-mutex package provides a mutual exclusion mechanism (mutex) for asynchronous operations in JavaScript. This is useful when you need to ensure that only one piece of code can access a particular resource or execute a specific task at a time, even in a concurrent or asynchronous environment.

What are async-mutex's main functionalities?

Mutex

The Mutex class allows you to create a lock that can be used to protect a critical section of code so that only one caller can execute it at a time.

const { Mutex } = require('async-mutex');
const mutex = new Mutex();

async function criticalSection() {
  const release = await mutex.acquire();
  try {
    // Perform the critical task that must not be interrupted
  } finally {
    release();
  }
}

Semaphore

The Semaphore class is similar to Mutex but allows multiple concurrent accesses to a resource, with the maximum number of concurrent accesses specified during the creation of the Semaphore.

const { Semaphore } = require('async-mutex');
const semaphore = new Semaphore(2);

async function limitedAccessFunction() {
  const [value, release] = await semaphore.acquire();
  try {
    // Perform a task that should only allow 2 concurrent accesses
  } finally {
    release();
  }
}

Other packages similar to async-mutex

Keywords

FAQs

Package last updated on 27 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc